﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Joyintech.Model.inpiao365;
using Joyintech.BLL.inpiao365;
using Joyintech.Common;
using System.IO;
using System.Data;

namespace Joyintech.WinService.inpiao365
{
    class Program
    {
        #region 变量定义

        /// <summary>
        /// 线程
        /// </summary>
        private static Thread thread;

        #endregion

        #region 主函数

        static void Main(string[] args)
        {
            
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "启动两个线程：1执行定时生成操作2定时更新缓存数据");
            CreateManageThreads();
        }

        #endregion

        #region 多线程

        /// <summary>
        /// 创建线程
        /// </summary>
        private static void CreateManageThreads()
        {
            thread = new Thread(new ThreadStart(ManageThreads));

            thread.Start();
        }

        /// <summary>
        /// 循环线程
        /// </summary>
        private static void ManageThreads()
        {
            while (thread.ThreadState == ThreadState.Running)
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "启动线程操作");
                Thread[] subTread = new Thread[2];

                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "线程1执行定时生成操作");
                subTread[0] = new Thread(new ParameterizedThreadStart(CreateFunction));
                subTread[0].Start(new object());

                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "线程1定期更新缓存数据");
                subTread[1] = new Thread(new ParameterizedThreadStart(RefreshMemcached));
                subTread[1].Start(new object());

                Thread.Sleep(50000);
            }
        }

        #endregion

        #region 定时生成文件

        private static void CreateFunction(object obj)
        { 
            //思路：
            //1、取出所有的任务计划，根据当前时间点，判断是否需要执行
            //2、生成完成后，更新本次执行时间

            List<createTask> taskList = new List<createTask>();

            #region 取出所有的任务计划

            List<createTask> list = new createTask_BLL().GetModelList("");

            if (list != null && list.Count > 0)
            {
                foreach (createTask item in list)
                {
                    switch (item.FrequencyType)
                    {
                        case "Month":
                            CreateMonth(item);
                            break;
                        case "Week":
                            CreateWeek(item);
                            break;
                        case "Day":
                            CreateDay(item);
                            break;
                        case "Hour":
                            CreateHour(item);
                            break;
                        case "1"://分钟
                            CreateMinute(item);
                            break;
                        case "5040"://周
                            CreateWeekN(item);
                            break;
                        case "720"://天
                            CreateDayN(item);
                            break;
                        case "12"://小时
                            CreateHourN(item);
                            break;
                    }
                }
            }

            #endregion 取出所有的任务计划
        }

        #endregion

        #region 每月一次

        /// <summary>
        /// 每月一次
        /// </summary>
        /// <param name="item"></param>
        private static void CreateMonth(createTask item)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "如果上次执行的年月等于当前的年月，则说明本月已经执行过一次");
            if (item.LastExecuteDate.Value.ToString("yyyy-MM") == DateTime.Now.ToString("yyyy-MM"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "拼接得到当前月的执行时间");
            DateTime currenMonth = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-") +  item.StartDay.Value + " " + item.StartHour);

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断当前时间是否等于当前月的执行时间");
            if (DateTime.Now.ToString("yyyy-MM-dd HH") != currenMonth.ToString("yyyy-MM-dd HH"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "调用生成函数，分成Channel、Content、File三种类型");
            switch (item.TaskType)
            { 
                case "Channel":
                    CreateChannel(item);
                    break;
                case "Content":
                    CreateContent(item);
                    break;
                case "File":
                    CreateFile(item);
                    break;
            }
        }

        #endregion

        #region 每周一次

        /// <summary>
        /// 每周一次
        /// </summary>
        /// <param name="item"></param>
        private static void CreateWeek(createTask item)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "如果上次执行的年月日时等于当前的年月日时，则说明本周已经执行过一次");
            if (item.LastExecuteDate.Value.ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断今天是一周中的第几天");
            int WeekDay = 0;

            DayOfWeek currenDayOfWeek = DateTime.Now.DayOfWeek;

            switch (currenDayOfWeek)
            {
                case System.DayOfWeek.Monday:
                    WeekDay = 1;
                    break;
                case System.DayOfWeek.Tuesday:
                    WeekDay = 2;
                    break;
                case System.DayOfWeek.Wednesday:
                    WeekDay = 3;
                    break;
                case System.DayOfWeek.Thursday:
                    WeekDay = 4;
                    break;
                case System.DayOfWeek.Friday:
                    WeekDay = 5;
                    break;
                case System.DayOfWeek.Saturday:
                    WeekDay = 6;
                    break;
                case System.DayOfWeek.Sunday:
                    WeekDay = 7;
                    break;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断今天【星期几】是否等于任务计划中的【星期几】");
            if (WeekDay != item.StartWeekday.Value)
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "调用生成函数，分成Channel、Content、File三种类型");
            switch (item.TaskType)
            {
                case "Channel":
                    CreateChannel(item);
                    break;
                case "Content":
                    CreateContent(item);
                    break;
                case "File":
                    CreateFile(item);
                    break;
            }
        }

        #endregion

        #region 每天一次

        /// <summary>
        /// 每天一次
        /// </summary>
        /// <param name="item"></param>
        private static void CreateDay(createTask item)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "如果上次执行的年月日等于当前的年月日，则说明今天已经执行过一次");
            if (item.LastExecuteDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断当前小时是否等于任务的小时");
            if (DateTime.Now.Hour != item.StartHour.Value)
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "调用生成函数，分成Channel、Content、File三种类型");
            switch (item.TaskType)
            {
                case "Channel":
                    CreateChannel(item);
                    break;
                case "Content":
                    CreateContent(item);
                    break;
                case "File":
                    CreateFile(item);
                    break;
            }
        }

        #endregion

        #region 每小时一次

        /// <summary>
        /// 每小时一次
        /// </summary>
        /// <param name="item"></param>
        private static void CreateHour(createTask item)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "如果上次执行的年月日时等于当前的年月日时，则说明当前的时间点已经执行过一次");
            if (item.LastExecuteDate.Value.ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "调用生成函数，分成Channel、Content、File三种类型");
            switch (item.TaskType)
            {
                case "Channel":
                    CreateChannel(item);
                    break;
                case "Content":
                    CreateContent(item);
                    break;
                case "File":
                    CreateFile(item);
                    break;
            }
        }

        #endregion

        #region 每N分钟一次

        /// <summary>
        /// 每N分钟一次
        /// </summary>
        /// <param name="item"></param>
        private static void CreateMinute(createTask item)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "如果上次执行的年月日时分+N分钟等于当前的年月日时分，则说明当前的时间点已经执行过一次");
            if (item.LastExecuteDate.Value.AddMinutes(item.PeriodIntervalMinute.Value).ToString("yyyy-MM-dd HH:mm") == DateTime.Now.ToString("yyyy-MM-dd HH:mm"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "调用生成函数，分成Channel、Content、File三种类型");
            switch (item.TaskType)
            {
                case "Channel":
                    CreateChannel(item);
                    break;
                case "Content":
                    CreateContent(item);
                    break;
                case "File":
                    CreateFile(item);
                    break;
            }
        }

        #endregion

        #region 每N周一次

        /// <summary>
        /// 每N周一次
        /// </summary>
        /// <param name="item"></param>
        private static void CreateWeekN(createTask item)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "如果上次执行的年月日+N周等于当前的年月日，则说明当前的时间点已经执行过一次");
            if (item.LastExecuteDate.Value.AddDays(item.PeriodIntervalMinute.Value * 7).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "调用生成函数，分成Channel、Content、File三种类型");
            switch (item.TaskType)
            {
                case "Channel":
                    CreateChannel(item);
                    break;
                case "Content":
                    CreateContent(item);
                    break;
                case "File":
                    CreateFile(item);
                    break;
            }
        }

        #endregion

        #region 每N天一次

        /// <summary>
        /// 每N天一次
        /// </summary>
        /// <param name="item"></param>
        private static void CreateDayN(createTask item)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "如果上次执行的年月日+N天等于当前的年月日，则说明当前的时间点已经执行过一次");
            if (item.LastExecuteDate.Value.AddDays(item.PeriodIntervalMinute.Value).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "调用生成函数，分成Channel、Content、File三种类型");
            switch (item.TaskType)
            {
                case "Channel":
                    CreateChannel(item);
                    break;
                case "Content":
                    CreateContent(item);
                    break;
                case "File":
                    CreateFile(item);
                    break;
            }
        }

        #endregion

        #region 每N小时一次

        /// <summary>
        /// 每N小时一次
        /// </summary>
        /// <param name="item"></param>
        private static void CreateHourN(createTask item)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "如果上次执行的年月日时等于当前的年月日时，则说明当前的时间点已经执行过一次");
            if (item.LastExecuteDate.Value.AddHours(item.PeriodIntervalMinute.Value).ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH"))
            {
                return;
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "调用生成函数，分成Channel、Content、File三种类型");
            switch (item.TaskType)
            {
                case "Channel":
                    CreateChannel(item);
                    break;
                case "Content":
                    CreateContent(item);
                    break;
                case "File":
                    CreateFile(item);
                    break;
            }
        }

        #endregion

        #region 生成静态页

        #region 创建栏目页面

        /// <summary>
        /// 分别创建栏目页面
        /// </summary>
        private static void CreateChannel(createTask task)
        {
            string selectedNodeId = string.Empty;

            selectedNodeId = task.ServiceParameters;

            if (selectedNodeId == "")
            {
                return;
            }
            else
            {
                selectedNodeId = Utils.ClearLastChar(selectedNodeId);
            }

            List<systemNode> list = new List<systemNode>();

            list = new systemNode_BLL().GetModelList("NodeId in (" + selectedNodeId + ") order by NodeOrder");

            if (list != null && list.Count > 0)
            {
                foreach (systemNode nodeModel in list)
                {
                    systemTemplate model = new systemTemplate_BLL().GetModel(nodeModel.ChannelTemplateID.Value);

                    if (model == null)
                    {
                        continue;
                    }

                    string templatefileName = ConfigHelper.GetConfigString("AdminPath") + "/templates/" + model.RelatedFileName;

                    if (model.TemplateType == "ChannelTemplate")
                    {
                        templatefileName = ConfigHelper.GetConfigString("AdminPath") + "/templates/channel/" + model.RelatedFileName;
                    }
                    else if (model.TemplateType == "ContentTemplate")
                    {
                        templatefileName = ConfigHelper.GetConfigString("AdminPath") + "/templates/content/" + model.RelatedFileName;
                    }

                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "检查模板文件是否存在");
                    if (!Utils.FileExists(templatefileName))
                    {
                        continue;
                    }

                    VelocityHelper vh = new VelocityHelper();
                    vh.Init(ConfigHelper.GetConfigString("AdminPath") + "/templates/channel/");

                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "单页显示条数");
                    int ItemsPerPage = 15;

                    if (nodeModel.ItemsPerPage != null)
                    {
                        ItemsPerPage = nodeModel.ItemsPerPage.Value;
                    }

                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "获取列表总条数");
                    int ContentNum = nodeModel.ContentNum;

                    if (nodeModel.SelectTableCount != "")
                    {
                        ContentNum = new pageSplit_BLL().GetPagerTotalCount(nodeModel.SelectTableCount);
                    }

                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断分页数据是否超过指定的条数");
                    int PageCount = ContentNum % ItemsPerPage;

                    if (PageCount > 0)
                    {
                        PageCount = ContentNum / ItemsPerPage + 1;
                    }
                    else
                    {
                        PageCount = ContentNum / ItemsPerPage;
                    }

                    if (PageCount == 0)
                    {
                        string bllName = ConfigHelper.GetConfigString("BLL");

                        System.Reflection.Assembly BLL = System.Reflection.Assembly.Load(bllName);

                        Type[] types = BLL.GetTypes();

                        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + " 遍历程序集中的类");
                        foreach (Type item in types)
                        {
                            string className = item.ToString().Replace(bllName + ".", "");

                            object stu = item.Assembly.CreateInstance(item.ToString());

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "添加页面操作类BLL");
                            vh.Put(className, stu);
                        }

                        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "页面数");
                        vh.Put("pages", PageCount);

                        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "栏目实体");
                        vh.Put("channel", nodeModel);

                        string html = vh.Display(model.RelatedFileName);

                        string directory = model.FileCreatePath + "\\";

                        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断栏目页面文件夹是否存在，如果不存在则创建");
                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }

                        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "栏目页面名称，默认只有一页");
                        string fileName = directory + nodeModel.NodeID.ToString() + model.CreatedFileExtName;
                        

                        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "栏目有分页且页数>1时，则每个页面名称后面加“_页索引”");
                        if (PageCount > 1)
                        {
                            fileName = directory + nodeModel.NodeID.ToString() + model.CreatedFileExtName;
                        }

                        StreamWriter objSw = new StreamWriter(fileName, false, Encoding.GetEncoding(model.TemplateCharset));
                        objSw.WriteLine(html);
                        objSw.Flush();
                        objSw.Close();
                    }
                    else
                    {
                        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "返回生成多个列表页面");
                        for (int CurrentPageIndex = 1; CurrentPageIndex <= PageCount; CurrentPageIndex++)
                        {
                            PageSplit pager = new PageSplit();

                            pager.SetPage(vh, CurrentPageIndex, nodeModel.NodeID.ToString(), PageCount);

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "当前页记录开始索引");
                            int StartRowNum = ItemsPerPage * (CurrentPageIndex - 1) + 1;

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "当前面记录结束索引");
                            int EndRowNum = ItemsPerPage * CurrentPageIndex;

                            if (nodeModel.SelectTable != "")
                            {
                                DataSet ds = new pageSplit_BLL().GetPagerList(nodeModel.SelectTable, nodeModel.SelectTableOrderBy, StartRowNum, EndRowNum);

                                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                                {
                                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "向模板中加载列表数据");
                                    vh.Put("contents", ds.Tables[0]);
                                }
                                else
                                {
                                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "向模板中加载空列表数据");
                                    vh.Put("contents", new DataTable());
                                }
                            }
                            else
                            {
                                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "获取当前分页的内容列表");
                                List<systemNodeContent> contentList = new systemNodeContent_BLL().GetModelList(nodeModel.NodeID, StartRowNum, EndRowNum);
                                vh.Put("contents", contentList);
                            }

                            string bllName = ConfigHelper.GetConfigString("BLL");

                            System.Reflection.Assembly BLL = System.Reflection.Assembly.Load(bllName);

                            Type[] types = BLL.GetTypes();

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + " 遍历程序集中的类");
                            foreach (Type item in types)
                            {
                                string className = item.ToString().Replace(bllName + ".", "");

                                object stu = item.Assembly.CreateInstance(item.ToString());

                                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "添加页面操作类BLL");
                                vh.Put(className, stu);
                            }

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "页面数");
                            vh.Put("pages", PageCount);
                            vh.Put("page", CurrentPageIndex);

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "栏目实体");
                            vh.Put("channel", nodeModel);

                            string html = vh.Display(model.RelatedFileName);

                            string directory = model.FileCreatePath + "\\";

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断栏目页面文件夹是否存在，如果不存在则创建");
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "栏目页面名称，默认只有一页");
                            string fileName = directory + nodeModel.NodeID.ToString() + model.CreatedFileExtName;
                            //string fileName = directory + model.CreatedFileFullName.ToString() + model.CreatedFileExtName;

                            //if (model.CreatedFileFullName.Trim().Equals(""))
                            //{
                            //    fileName = directory + nodeModel.NodeID.ToString() + model.CreatedFileExtName;
                            //}

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "栏目有分页且页数>1时，则每个页面名称后面加“_页索引”");
                            if (PageCount > 1)
                            {
                                fileName = directory + nodeModel.NodeID.ToString() + "_" + CurrentPageIndex.ToString() + model.CreatedFileExtName;

                                //if (model.CreatedFileFullName.Trim().Equals(""))
                                //{
                                //    fileName = directory + nodeModel.NodeID.ToString() + "_" + CurrentPageIndex.ToString() + model.CreatedFileExtName;
                                //}
                            }

                            StreamWriter objSw = new StreamWriter(fileName, false, Encoding.GetEncoding(model.TemplateCharset));
                            objSw.WriteLine(html);
                            objSw.Flush();
                            objSw.Close();
                        }
                    }
                }
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "更新任务执行时间");
            UpdateCreateTime(task);
        }

        #endregion

        #region 创建内容页面

        /// <summary>
        /// 创建内容页面
        /// </summary>
        /// <param name="task"></param>
        private static void CreateContent(createTask task)
        {
            string selectedNodeId = string.Empty;

            selectedNodeId = task.ServiceParameters;

            if (selectedNodeId == "")
            {
                return;
            }
            else
            {
                selectedNodeId = Utils.ClearLastChar(selectedNodeId);
            }

            List<systemNode> list = new List<systemNode>();

            list = new systemNode_BLL().GetModelList("NodeId in (" + selectedNodeId + ") order by NodeOrder");

            if (list != null && list.Count > 0)
            {
                pageSplit_BLL pageBll = new pageSplit_BLL();

                foreach (systemNode nodeModel in list)
                {
                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "取得内容模板");
                    systemTemplate model = new systemTemplate_BLL().GetModel(nodeModel.ContentTemplateID.Value);

                    if (model == null)
                    {
                        continue;
                    }

                    string templatefileName = ConfigHelper.GetConfigString("AdminPath") + "/templates/" + model.RelatedFileName;

                    if (model.TemplateType == "ChannelTemplate")
                    {
                        templatefileName = ConfigHelper.GetConfigString("AdminPath") + "/templates/channel/" + model.RelatedFileName;
                    }
                    else if (model.TemplateType == "ContentTemplate")
                    {
                        templatefileName = ConfigHelper.GetConfigString("AdminPath") + "/templates/content/" + model.RelatedFileName;
                    }

                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "检查模板文件是否存在");
                    if (!Utils.FileExists(templatefileName))
                    {
                        continue;
                    }

                    VelocityHelper vh = new VelocityHelper();
                    vh.Init(ConfigHelper.GetConfigString("AdminPath") + "/templates/content/");

                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "获取当前栏目内容数据集");
                    DataSet ds = new DataSet();

                    ds = pageBll.GetList(nodeModel.SelectTable);

                    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "返回生成多个列表页面");
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "页面内容实体");
                            vh.Put("content", dr);

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "页面栏目实体");
                            vh.Put("channel", nodeModel);

                            string html = vh.Display(model.RelatedFileName);

                            //string directory = ConfigHelper.GetConfigString("ContentPath");

                            string directory = model.FileCreatePath + "\\";

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断栏目页面文件夹是否存在，如果不存在则创建");
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }

                            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "内容页面名称，默认只有一页");
                            string fileName = directory + "\\" + dr[nodeModel.ContentTableKey].ToString() + model.CreatedFileExtName;

                            StreamWriter objSw = new StreamWriter(fileName, false, Encoding.GetEncoding(model.TemplateCharset));
                            objSw.WriteLine(html);
                            objSw.Flush();
                            objSw.Close();
                        }
                    }
                }
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "更新任务执行时间");
            UpdateCreateTime(task);
        }

        #endregion

        #region 创建文件页面

        private static void CreateFile(createTask task)
        {
            string selectedNodeId = string.Empty;

            selectedNodeId = task.ServiceParameters;

            if (selectedNodeId == "")
            {
                return;
            }
            else
            {
                selectedNodeId = Utils.ClearLastChar(selectedNodeId);
            }

            List<systemTemplate> list = new systemTemplate_BLL().GetModelList("TemplateId in (" + selectedNodeId + ") order by TemplateId");

            foreach (systemTemplate model in list)
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "生成文件页");
                VelocityHelper vh = new VelocityHelper();
                vh.Init(ConfigHelper.GetConfigString("AdminPath") + "/templates/file/");

                string bllName = ConfigHelper.GetConfigString("BLL");
                System.Reflection.Assembly BLL = System.Reflection.Assembly.Load(bllName);

                Type[] types = BLL.GetTypes();

                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + " 遍历程序集中的类");
                foreach (Type type in types)
                {
                    string className = type.ToString().Replace(bllName + ".", "");

                    object stu = type.Assembly.CreateInstance(type.ToString());

                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "添加页面操作类BLL");
                    vh.Put(className, stu);
                }

                string html = vh.Display(model.RelatedFileName);

                string directory = model.FileCreatePath;

                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "判断栏目页面文件夹是否存在，如果不存在则创建");
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "文件页面名称，默认只有一页");
                string fileName = directory + model.CreatedFileFullName + model.CreatedFileExtName;

                StreamWriter objSw = new StreamWriter(fileName, false, Encoding.GetEncoding(model.TemplateCharset));
                objSw.WriteLine(html);
                objSw.Flush();
                objSw.Close();
            }

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:dd") + "更新任务执行时间");
            UpdateCreateTime(task);
        }

        #endregion

        #region 更新任务执行时间

        /// <summary>
        /// 更新任务执行时间
        /// </summary>
        /// <param name="task"></param>
        private static void UpdateCreateTime(createTask task)
        {
            task.LastExecuteDate = DateTime.Now;

            new createTask_BLL().Update(task);
        }

        #endregion

        #endregion

        #region 定时更新缓存数据

        private static void RefreshMemcached(object obj)
        {

        }

        #endregion
    }
}
